#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

from subprocess import Popen, PIPE

from config import Config


config = Config()


class Utils():
    def listdirs(self, directory):
        return [f for f in os.listdir(directory) if os.path.isdir(os.path.join(directory, f))]
    
    def compressdir(self, source):
        # ejecutamos tar -c0 {source}
        p1 = Popen([config.TAR_BIN, '-cO', source], stdout=PIPE)
        # ejecutamos bzip2 -c
        p2 = Popen([config.BZIP2_BIN, '-c'], stdin=p1.stdout, stdout=PIPE)
        # devolvemos el .tar.bz2
        return p2.communicate()[0]
